package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.MessageRtc;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.MessageRtcMapper;
import com.zrwl.poscloud.xo.service.MessageRtcService;
import com.zrwl.poscloud.xo.vo.MessageRtcVO;
/**
 * 实时通讯 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-17
 */
@Service
public class MessageRtcServiceImpl extends SuperServiceImpl<MessageRtcMapper,MessageRtc> implements MessageRtcService {

    @Autowired
    private MessageRtcService messageRtcService;
    @Override
    public IPage<MessageRtc> getPageList(MessageRtcVO messageRtcVO){
       QueryWrapper<MessageRtc> queryWrapper = new QueryWrapper<>();
       if (StringUtils.isNotEmpty(messageRtcVO.getKeyword()) && !StringUtils.isEmpty(messageRtcVO.getKeyword().trim())) {
            queryWrapper.like("name", messageRtcVO.getKeyword().trim());
       }
       Page<MessageRtc> page = new Page<>();
       page.setCurrent(messageRtcVO.getCurrentPage());
       page.setSize(messageRtcVO.getPageSize());
       queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
       queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
       IPage<MessageRtc> pageList = messageRtcService.page(page, queryWrapper);
       List<MessageRtc> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<MessageRtc> getAllList(MessageRtcVO messageRtcVO){
        QueryWrapper<MessageRtc> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<MessageRtc> list = messageRtcService.list(queryWrapper);
        return list;
}
    @Override
    public String add(MessageRtcVO messageRtcVO){
        MessageRtc entity = new MessageRtc();
        BeanUtils.copyProperties(messageRtcVO, entity, SysConf.STATUS);
        entity.insert();
        messageRtcVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(MessageRtcVO messageRtcVO){
        MessageRtc entity = messageRtcService.getById(messageRtcVO.getUid());
        BeanUtils.copyProperties(messageRtcVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(MessageRtcVO messageRtcVO){
        MessageRtc entity = messageRtcService.getById(messageRtcVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
